package dao

import (
	"pay/inits"
	"pay/model"
)

func Login(name string) (user model.User, err error) {
	err = inits.DB.Where("name = ?", name).Find(&user).Limit(1).Error
	if err != nil {
		return model.User{}, err
	}
	return user, nil
}

func Register(name string, password string) (user model.User, err error) {
	user = model.User{
		Name:     name,
		Password: password,
	}
	err = inits.DB.Create(&user).Error
	if err != nil {
		return model.User{}, err
	}
	return user, nil
}

func List() (user []model.User, err error) {
	err = inits.DB.Find(&user).Error
	if err != nil {
		return []model.User{}, err
	}
	return user, nil
}

func WhereList[T any](where *T, data *T) bool {
	err := inits.DB.Where(where).Find(data).Limit(1).Error
	if err != nil {
		return false
	}
	return true
}
